/**
 * DiggApiNet - Digg API .NET Wrapper
 * 
 * Author: Sean Hickey
 * Link: http://www.headzoo.com/digg_api_net
 * License: GPL v2 ( http://www.gnu.org/licenses/gpl.txt )
 */
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Collections;

namespace DiggApiNet
{
    public class DiggComments : DiggReturnBaseCollection, IEnumerable
    {
        private List<DiggComment> _comments;
        public List<DiggComment> Comments
        {
            get
            {
                return _comments;
            }
            set
            {
                _comments = value;
            }
        }
        public DiggComment this[int index]
        {
            get
            {
                return _comments[index];
            }
            set
            {
                _comments[index] = value;
            }
        }

        public DiggComments()
        {
            _comments = new List<DiggComment>();
        }
        public DiggComments(XmlDocument xml_doc) : base(xml_doc, "events")
        {
            _comments = new List<DiggComment>();
            if (xml_doc.SelectSingleNode("events") == null
                || xml_doc.SelectSingleNode("events").SelectNodes("comment") == null) {
                throw new DiggApiException("XML response appears to be malformed, or contains unexpected data.");
            }
            foreach (XmlNode node in xml_doc.SelectSingleNode("events").SelectNodes("comment")) {
                _comments.Add(new DiggComment(node));
            }
        }

        public IEnumerator GetEnumerator()
        {
            return _comments.GetEnumerator();
        }
    }
}
